/*
    Copyright (c) 2008-2009, Prashanta Shrestha All Rights Reserved.
    Available under GNU Lesser General Public License >= 3.0 as published by the Free Software Foundation.
    see <http://www.gnu.org/licenses/>
*/
/*-------------------------------------------------------------------------------------
  CLASS : qDojo.dijix.MenuItem
  ==================================
  - Navigation button widget with sliding effect onmouseover

  -------------------------------------------------------------------------------------*/
dojo.provide("qDojo.dijix.MenuItem");

dojo.require("dijit._Widget");
dojo.require("dijit._Templated");
dojo.require("dijit._Container");

dojo.declare("qDojo.dijix.MenuItem", [dijit._Widget ,  dijit._Templated , dijit._Contained ] , {

		templateString: " <div dojoAttachPoint=\"outerNode\" dojoAttachEvent=\"onmouseenter:_onOver,onmouseleave:_onLeave,onclick:_onClick\">" + 
							"<span dojoAttachPoint=\"iconNode\" class=\"dijixMenuItemIcon\">&nbsp;</span><span class=\"dijixMenuItemLabel\" dojoAttachPoint=\"labelNode\"></span>"+
						" </div>",
		label : "",
		event: "",
		active: false,
		iconClass: "",
		iconImage: "",
		separator: false,		
		method: "",
		// ----------------------------------------------------------------------
		//	Post create widget 
		// ======================================================================
		postCreate: function()
		{		
			this.inherited(arguments);
            if(!this.separator)
			{							
				this.outerNode.className = "dijixMenuItemNormal";
				this.outerNode.style.cssText = "padding: 0px;width: 100%;height: 25px;cursor: pointer;	position: relative;border-bottom:1px solid #AAAAAA;border-top:1px solid #EEEEEE;display:shown";
							
				if(this.iconClass)
					this.iconNode.className += " "+this.iconClass;
				else if(this.iconImage)
				    this.iconNode.innerHTML = "<img src='"+this.iconImage+"' style='width:16px; height:16px'>";	 									
			}else
			{			
				this.outerNode.className = "dijixMenuItemSeparator";
				this.iconNode.style.width = "0px";
				this.labelNode.style.left = "0px";
				this.labelNode.style.color = "#FFFFFF";
			}			
			this.labelNode.innerHTML = this.label;							
		},
		// ----------------------------------------------------------------------
		//	Activate this child
		// ======================================================================
		activate: function()
		{
			if(!this.separator){
			    this.getParent().deactivateChildren();
				this.outerNode.className = "dijixMenuItemActive";				
				this.outerNode.style.cursor="auto";				
				this.active = true;
			}
		},
		// ----------------------------------------------------------------------
		//	Deactivate this child
		// ======================================================================
		deactivate: function()
		{
			if(!this.separator){
				this.outerNode.className = "dijixMenuItemNormal";
				this.outerNode.style.cursor="pointer";
				this.active = false;
			}
		},
		// ----------------------------------------------------------------------
		//	On mouse over event
		// ======================================================================
		_onOver: function()
		{
			if(!this.separator && !this.active)
				this.outerNode.className = "dijixMenuItemOver";										
		},
		// ----------------------------------------------------------------------
		//	On mouse leave event
		// ======================================================================
		_onLeave: function()
		{
			if(!this.separator && !this.active)
				this.outerNode.className = "dijixMenuItemNormal";
		},			
		// ----------------------------------------------------------------------
		//	On Click event
		// ======================================================================
		_onClick: function()
		{	
		    if( !this.separator && !this.active )
		    {
		        this.getParent().childClicked(this);
                this.onClickItem();
            }	
		},
		// ----------------------------------------------------------------------
		//	Something to connect with
		// ======================================================================
		onClickItem: function()
		{			      			                                                                                                      
		}	
});